import Router from '@koa/router';
import MenuController from '@/controllers/MenuController';
import { auth, requirePermission } from '@/middlewares';
import { PermissionAction } from '@/types';

const router = new Router({
  prefix: '/api/menus',
});

/**
 * 菜单路由
 */

// 获取用户菜单（根据权限）
router.get('/user-menus', auth, MenuController.userMenus.bind(MenuController));

// 获取用户按钮权限
router.get('/user-buttons', auth, MenuController.userButtons.bind(MenuController));

// 获取菜单树
router.get('/tree', auth, requirePermission('menu', PermissionAction.READ), MenuController.tree.bind(MenuController));

// 获取菜单列表
router.get('/', auth, requirePermission('menu', PermissionAction.READ), MenuController.list.bind(MenuController));

// 获取菜单详情
router.get('/:id', auth, requirePermission('menu', PermissionAction.READ), MenuController.detail.bind(MenuController));

// 创建菜单
router.post('/', auth, requirePermission('menu', PermissionAction.CREATE), MenuController.create.bind(MenuController));

// 更新菜单
router.put('/:id', auth, requirePermission('menu', PermissionAction.UPDATE), MenuController.update.bind(MenuController));

// 删除菜单
router.delete('/:id', auth, requirePermission('menu', PermissionAction.DELETE), MenuController.delete.bind(MenuController));

export default router;

